/**
 * 
 */
package com.java.test.timer;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.java.test.system.dto.LoginAccountInfo;
import com.java.test.util.JsonUtil;
import com.java.test.util.RedisUtil;
import com.java.test.util.TokenUtil;

/**
 * @author Administrator
 *
 */

@Component
@EnableScheduling
public class SsoTimer {

	@Autowired
	private RedisUtil redisUtil;

	@Scheduled(cron = "*/1 * * * * ?")
	public void runfirst() {

	}

	public void dealonlineuser() {

		List<Object> obj = redisUtil.hsetvalues("ONLINE_USER");

		if (obj == null || obj.size() <= 0) {
			return;
		}
		obj.forEach(b -> {
			List<LoginAccountInfo> ilist = JsonUtil.jsonArray2List(b.toString(), LoginAccountInfo.class);
			List<LoginAccountInfo> tlist = new ArrayList<LoginAccountInfo>();
			ilist.forEach(info -> {
				if (info == null)
					return;
				String token = info.getTokenVerify();

				boolean isucess = TokenUtil.verify(token, null);
				// 失效
				if (isucess) {
					tlist.add(info);
				}
			});
			if (tlist.size() > 0) {
				redisUtil.hset("ONLINE_USER", ilist.get(0).getLoginAccout(), JsonUtil.obj2json(ilist));
			}

		});

	}

}
